<template>
  <div class="patientMain">
    <div class="patientMain_top">
      <div class="patientMain_top_left">
        <div class="patientMain_top_left_title"><h3>问诊室</h3></div>
        <div class="patientMain_top_left_time">{{ time }}</div>
      </div>
      <div class="patientMain_top_right">
        <van-icon name="edit " size=".8rem" color="#007aff" />
      </div>
    </div>
    <communicateList :list="list" />
  </div>
</template>

<script>
import communicateList from "@/components/commonComponents/communicateList.vue";
import axios from "axios";
export default {
  name: "patientMain",
  components: {
    communicateList,
  },
  data() {
    return {
      time:'',
      appuserInfo:{},
      list: [
        // {
        //   id: 1,
        //   imgUrl: "https://q1.qlogo.cn/g?b=qq&nk=1848257116&s=100",
        //   name: "罗汉",
        //   message: "医生好",
        //   time: "今天",
        // },
        // {
        //   id: 2,
        //   imgUrl: "https://q1.qlogo.cn/g?b=qq&nk=1848857116&s=100",
        //   name: "Johnny Watson",
        //   message:
        //     "医生好医生好医生好医生好医生好医生好医生好医生好医生好医生好",
        //   time: "昨天",
        // },
      ],
    };
  },
  created: function () {
    this.getUserInfo();


      //请求当前用户聊天列表
      const options = {
        method: 'GET',
        url: 'http://106.54.189.155:6768/chat/findRoomListByUserId',
        headers: {Accept: '*/*'}
      };
      axios.request(options).then(response=>{
        this.list=response.data.data;
        console.log(response.data);
      }).catch(function (error) {
        console.error(error);
      });

  },
  mounted() {
    this.format();
  },

  methods: {
    getUserInfo() {
      const storage = window.localStorage;
      const json = storage.getItem('appuserInfo');
      this.appuserInfo = JSON.parse(json)
      console.log(this.appuserInfo);
    },

    toCommunication() {
      this.$router.push({ path: "/home/chatRoom" });
    },

    //获取当前时间
      format() {
        const nowDate = new Date();
        const date = {
          year: nowDate.getFullYear(),
          month: nowDate.getMonth() + 1,
          date: nowDate.getDate(),
        }
        const newmonth = date.month > 10 ? date.month : '0' + date.month
        const day = date.date > 10 ? date.date : '0' + date.date
        this.time = date.year + '.' + newmonth + '.' + day
      },
  },
};
</script>

<style lang="scss" scope>
.patientMain {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  overflow-y: scroll;
  background-color: #fafafa;

  &_top {
    padding: 20px 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: #f1f1f1;

    &_left {
      &_title {
        font-size: 20px;
        & h3 {
          margin: 10px 0;
        }
      }
      &_time {
        font-size: 16px;
      }
    }
  }
}
</style>
